package fr.istic.linkedcv.client.presentation.views.impl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Widget;

import fr.istic.linkedcv.client.presentation.Ui;
import fr.istic.linkedcv.client.presentation.views.View;
import fr.istic.linkedcv.client.services.PersonneService;
import fr.istic.linkedcv.client.services.PersonneServiceAsync;

public class Logout extends View {
	PersonneServiceAsync personneServiceAsync = GWT.create(PersonneService.class);
	public Logout(Ui ui) {
		super(ui);
	}

	@Override
	public void build() {
		personneServiceAsync.logout(new AsyncCallback<Boolean>() {
			
			@Override
			public void onSuccess(Boolean result) {
				if(result){
					ui.getControle().setLogged(false);
					ui.addHistoryItem("login");
				}else{
					Window.alert("echec lors de la déconnexion.");
				}
				
			}
			
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				
			}
		});
	}

	@Override
	public Widget getWidget() {
		// TODO Auto-generated method stub
		return null;
	}

}
